*********************************
* IRCA and Redistricting
* Navid Sabet and Noam Yuchtman
* Table C3: Figure 9 in table form
*******************************

//Setup
	do "$dofiles/00_setup.do"

//Load master data
	use irca_gerrymander.dta, clear
	
	
	//Controls
	global controls  c.pop1990#i.p102_full c.inc_pc1990#i.p102_full  c.age_share1990#i.p102_full c.unemployment_1990#i.p102_full c.educ1990##i.p102_full c.births_1990#i.p102_full c.black_share1990#i.p102_full c.white_share1990#i.p102_full
	
	global controls_full  c.pop1990##i.p102_full##i.legal_control_kaplan1991 c.inc_pc1990##i.p102_full##i.legal_control_kaplan1991  c.age_share1990##i.p102_full##i.legal_control_kaplan1991 c.unemployment_1990##i.p102_full##i.legal_control_kaplan1991 c.educ1990##i.p102_full##i.legal_control_kaplan1991 c.births_1990##i.p102_full##i.legal_control_kaplan1991 c.black_share1990##i.p102_full##i.legal_control_kaplan1991 c.white_share1990##i.p102_full##i.legal_control_kaplan1991
	
	//VRA Controls: first one is VRA horse race v IRCA; second is horse race of VRA v. Legal Controls.
	global vra_control i.vra_covered##i.p102_full
	global vra_full i.vra_covered##i.p102_full##i.legal_control_kaplan1991 
	
	//Extra controls
	global extras c.povrate_1990#i.p102_full c.hsd_share1990#i.p102_full c.spr010_1990#i.p102_full c.spr030_1990#i.p102_full c.housing_value_1990#i.p102_full c.crime_1990#1.p102_full
	
	 //1980 Controls
	global controls1980 c.population_bea1980#i.p102_full c.income_pc1980#i.p102_full  c.age_share1980#i.p102_full c.edu6351980#i.p102_full c.births_1980#i.p102_full c.black_share1980#i.p102_full c.white_share1980#i.p102_full
	
	//Controls pre post 1980 redistricting.
	global controls97 c.pop1990#i.p97_full c.inc_pc1990#i.p97_full  c.age_share1990#i.p97_full c.unemployment_1990#i.p97_full c.educ1990##i.p97_full c.births_1990#i.p97_full c.black_share1990#i.p97_full c.white_share1990#i.p97_full
		
	//Vra controls: pre post 1980 redistricting
	global vra_control97 i.vra_covered##i.p97_full
	
	//Fixed effects
	global fe id congress#StateFIPS c.hisp_share1980#i.congress i.unassigned_county#i.congress 
	
	//Clustering
	global cluster id
	
****************
* Hispanic Wins the Seat
****************
eststo clear
	 //Baseline
	reghdfe hisp_representative_county $controls $vra_control c.irca_std##1.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_representative_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //No controls
	reghdfe hisp_representative_county c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_representative_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Extra controls
	reghdfe hisp_representative_county $controls $vra_control $extras c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_representative_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//1980 Controls
	reghdfe hisp_representative_county $controls1980 $vra_control c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)	
	sum hisp_representative_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 	
	
	//Interacted Observables (Fully Saturated)
	reghdfe hisp_representative_county $controls_full $vra_full c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_representative_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)	
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Alternative Legal Control
	reghdfe hisp_representative_county $controls $vra_control c.irca_std##1.p102_full##ib2.arp_nocommission [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_representative_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Using Hispanic share instead of imputing
	reghdfe hisp_representative_county $controls $vra_control c.irca_pc1990_hisp_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_representative_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Drop imputed counties
	reghdfe hisp_representative_county $controls $vra_control c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 if unassigned_county == 0 [weight = cuts], a($fe) cluster($cluster)
	sum hisp_representative_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //Only single district counties
	reghdfe hisp_representative_county $controls $vra_control c.irca_std##1.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] if  cuts==1, a($fe) cluster($cluster)
	sum hisp_representative_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Drop minority-majority counties
	reghdfe hisp_representative_county $controls $vra_control c.irca_std##1.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] if StateFIPS!=35, a($fe) cluster($cluster)
	sum hisp_representative_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Falsification
	reghdfe hisp_representative_county $controls97 $vra_control97 c.irca_std##i.p97_full##ib2.legal_control_kaplan1981 [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_representative_county if e(sample) & p97_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	 

			
esttab 	using "${output}/panel_hisprep.tex", replace booktabs fragment  /// 
			label nomtitles nonumbers noobs nonote nogaps noline  ///
			se star(* 0.1 ** 0.05 *** 0.01) sfmt(%9.2fc) ///
				rename(1.p102_full#c.irca_pc1990_hisp_std 1.p102_full#c.irca_std ///
				1.p102_full#0.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102_full#0.legal_control_kaplan1991#c.irca_std ///
				1.p102_full#1.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std ///
				1.p97_full#c.irca_std 1.p102_full#c.irca_std ///
				1.p97_full#0.legal_control_kaplan1981#c.irca_std 1.p102_full#0.legal_control_kaplan1991#c.irca_std ///
				1.p97_full#1.legal_control_kaplan1981#c.irca_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std ///
				1.p102_full#1.arp_nocommission#c.irca_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std) ///
			keep(1.p102_full#c.irca_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std) /// 
			scalars("ymean $\bar{Y}_{Pre}$" "ysd $[S.D.]$") 

		//// \hspace{.5em} IRCA$_{90}$ $\times$ Post $\times$ D  
			/// \multicolumn{1}{|c}{	
			/// \cmidrule(lr){2-8} \cmidrule(lr){9-12}
			/// \multicolumn{7}{c}{
				
			
****************
* Dem Vote Share Congressional Elections
****************
eststo clear
	 //Baseline
	reghdfe d_share_county $controls $vra_control c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum d_share_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //No controls
	reghdfe d_share_county c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum d_share_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Extra controls
	reghdfe d_share_county $controls $vra_control $extras c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum d_share_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//1980 Controls
	reghdfe d_share_county $controls1980 $vra_control c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)	
	sum d_share_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 	
	
	//Interacted Observables (Fully Saturated)
	reghdfe d_share_county $controls_full $vra_full c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum d_share_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Alternative Legal Control
	reghdfe d_share_county $controls $vra_control c.irca_std##1.p102_full##ib2.arp_nocommission [weight = cuts] , a($fe) cluster($cluster)
	sum d_share_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Using Hispanic share instead of imputing
	reghdfe d_share_county $controls $vra_control c.irca_pc1990_hisp_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum d_share_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Drop imputed counties
	reghdfe d_share_county $controls $vra_control c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 if unassigned_county == 0 [weight = cuts], a($fe) cluster($cluster)
	sum d_share_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //Only single district counties
	reghdfe d_share_county $controls $vra_control c.irca_std##1.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] if cuts==1, a($fe) cluster($cluster)
	sum d_share_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //Drop minority-majority counties
	reghdfe d_share_county $controls $vra_control c.irca_std##1.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] if StateFIPS!=35, a($fe) cluster($cluster)
	sum d_share_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Falsification
	reghdfe d_share_county  $controls97 $vra_control97 c.irca_std##i.p97_full##ib2.legal_control_kaplan1981 [weight = cuts] , a($fe) cluster($cluster)
	sum d_share_county if e(sample) & p97_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
			

			 
esttab 	using "${output}/panel_demshare.tex", replace booktabs fragment  /// 
			label nomtitles nonumbers noobs nonote nogaps noline  ///
			se star(* 0.1 ** 0.05 *** 0.01) sfmt(%9.2fc) ///
				rename(1.p102_full#c.irca_pc1990_hisp_std 1.p102_full#c.irca_std ///
				1.p102_full#0.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102_full#0.legal_control_kaplan1991#c.irca_std ///
				1.p102_full#1.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std ///
				1.p97_full#c.irca_std 1.p102_full#c.irca_std ///
				1.p97_full#0.legal_control_kaplan1981#c.irca_std 1.p102_full#0.legal_control_kaplan1991#c.irca_std ///
				1.p97_full#1.legal_control_kaplan1981#c.irca_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std ///
				1.p102_full#1.arp_nocommission#c.irca_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std) ///
			keep(1.p102_full#c.irca_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std) ///
			scalars("ymean $\bar{Y}_{Pre}$" "ysd $[S.D.]$") 

		//// \hspace{.5em} IRCA$_{90}$ $\times$ Post $\times$ D  
			/// \multicolumn{1}{|c}{	
			/// \cmidrule(lr){2-8} \cmidrule(lr){9-12}
			/// \multicolumn{7}{c}{
				
				
****************
* Democrat wins the seat
****************
eststo clear
	 //Baseline
	reghdfe dem_rep_county $controls $vra_control c.irca_std##1.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum dem_rep_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //No controls
	reghdfe dem_rep_county c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum dem_rep_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Extra controls
	reghdfe dem_rep_county $controls $vra_control $extras c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum dem_rep_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//1980 Controls
	reghdfe dem_rep_county $controls1980 $vra_control c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)	
	sum dem_rep_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 	
	
	//Interacted Observables (Fully Saturated)
	reghdfe dem_rep_county $controls_full $vra_full c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum dem_rep_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Alternative Legal Control
	reghdfe dem_rep_county $controls $vra_control c.irca_std##1.p102_full##ib2.arp_nocommission [weight = cuts] , a($fe) cluster($cluster)
	sum dem_rep_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Using Hispanic share instead of imputing
	reghdfe dem_rep_county $controls $vra_control c.irca_pc1990_hisp_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts], a($fe) cluster($cluster)
	sum dem_rep_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Drop imputed counties
	reghdfe dem_rep_county $controls $vra_control c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 if unassigned_county == 0 [weight = cuts], a($fe) cluster($cluster)
	sum dem_rep_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //Only single district counties
	reghdfe dem_rep_county $controls $vra_control c.irca_std##1.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] if  cuts==1, a($fe) cluster($cluster)
	sum dem_rep_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Drop minority-majority counties
	reghdfe dem_rep_county $controls $vra_control c.irca_std##1.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] if StateFIPS!=35, a($fe) cluster($cluster)
	sum dem_rep_county if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Falsification
	reghdfe dem_rep_county $controls97 $vra_control97 c.irca_std##i.p97_full##ib2.legal_control_kaplan1981 [weight = cuts] , a($fe) cluster($cluster)
	sum dem_rep_county if e(sample) & p97_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	 

			
esttab 	using "${output}/panel_demseat.tex", replace booktabs fragment  /// 
			label nomtitles nonumbers noobs nonote nogaps noline  ///
			se star(* 0.1 ** 0.05 *** 0.01) sfmt(%9.2fc) ///
				rename(1.p102_full#c.irca_pc1990_hisp_std 1.p102_full#c.irca_std ///
				1.p102_full#0.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102_full#0.legal_control_kaplan1991#c.irca_std ///
				1.p102_full#1.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std ///
				1.p97_full#c.irca_std 1.p102_full#c.irca_std ///
				1.p97_full#0.legal_control_kaplan1981#c.irca_std 1.p102_full#0.legal_control_kaplan1991#c.irca_std ///
				1.p97_full#1.legal_control_kaplan1981#c.irca_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std ///
				1.p102_full#1.arp_nocommission#c.irca_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std) ///
			keep(1.p102_full#c.irca_std 1.p102_full#1.legal_control_kaplan1991#c.irca_std) ///
			scalars("ymean $\bar{Y}_{Pre}$" "ysd $[S.D.]$") 

		//// \hspace{.5em} IRCA$_{90}$ $\times$ Post $\times$ D  
			/// \multicolumn{1}{|c}{	
			/// \cmidrule(lr){2-8} \cmidrule(lr){9-12}
			/// \multicolumn{7}{c}{
				
***********************
*	Generate Table
**********************		
estfe est* // push FEs information from absorb argument in reghdfe command		
esttab  est*	using "${output}/tabC3.tex", replace booktabs ///
				nonote noobs nogaps compress noeqlines se drop(*) substitute(_ _)  ///
				mgroups("Empirical Specifications" "Sample Restrictions" "Placebo", pattern(1 0 0 0 0 0 0 1 0 0 1) ///
				prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
				mtitles("\makecell{Baseline \\ Model}" "\makecell{No \\ Covariates}" "\makecell{Extra \\ Covariates}" "\makecell{1980 \\ Covariates}" "\makecell{Interacted \\ Observables}" "\makecell{Alternative \\ Legal Control}" "\makecell{Hispanic \\ Impute}" "\makecell{Drop \\ Imputed}" "\makecell{Single-District \\ Counties}" "\makecell{Drop New \\ Mexico}" "\makecell{1980 \\ Placebo}") ///
				posthead( ///
				\midrule \multicolumn{@span}{l}{\emph{Panel A. Descriptive Representation: Hispanic Wins Seat}} \\ ///
					\input{${output}/panel_hisprep.tex} ///
					\midrule \multicolumn{@span}{l}{\emph{Panel B. Substantive Representation: Democratic Vote Share}} \\ ///
					\input{${output}/panel_demshare.tex} ///
					\midrule \multicolumn{@span}{l}{\emph{Panel C. Substantive Representation: Democrat Wins Seat}} \\ ///
					\input{${output}/panel_demseat.tex} ) ///
				scalars("N $N$" "clusters Clusters") sfmt(%9.3gc) ///
				star(* 0.1 ** 0.05 *** 0.01) 				
